<template>
	<view class="content">
		<view >
			<!-- <view class="row b-b">
				<text class="tit zy-required">真实姓名</text>
				<input class="input"   v-model="form.accountName"  placeholder="持卡人姓名" />
			</view> -->
			<view class="row b-b">
				<text class="tit zy-required">银行卡号</text>
				<input class="input" type="number"  v-model="form.cardNo"  placeholder="请输入您的银行卡卡号" />
			</view>
			<!-- <view class="row b-b">
				<text class="tit zy-required">手机号</text>
				<input class="input" type="number" v-model="form.bankcardPhone"  placeholder="请输入您的银行预留手机号码" />
			</view> -->
			<!-- <view class="row b-b">
				<text class="tit">开户行</text>
				<input class="input"   v-model="form.bankName"  placeholder="银行开户行"  disabled/>
			</view> -->
			<button class="add-btn" @click="confirmAdd" :disabled="submitAddress">提交</button>
		</view>
	</view>
</template>

<script>
	import {getBankInfoByCardNo} from '@/common/bank.js'
	export default {
		data() {
			return {
				countIndex: 0,
				count: [1],
				form: {                    
					bankCode: '',
					bankName: '',
					cardNo: '',
				},
				bankIndex: 0,
				submitAddress:true
			};
		},
		onShow() {
			this.verificationIdentityCard()
		},
		methods:{
			//查询是否实名认证
			verificationIdentityCard(){
				this.$util.doPostJson("/wx/saveSFZ", {}, {}, true).then(res => {
					if (res.data.code == this.$ResponseStatus.OK) {
						console.log("身份证验证",res.data)
						if(!res.data.data){
							this.identityCardStatus = false
						}else {
							this.userInfo = res.data.data
							this.form.idCard = this.userInfo.idCard
							this.form.realName = this.userInfo.realName
							this.identityCardStatus = true;
							this.submitAddress = false
						}
					}
				}).catch(error => {
					console.log(error)
				})
			},
			/**
			 * 确认添加
			 */
			confirmAdd() {
				if(!this.identityCardStatus){
					this.$util.showInfoToast("请实名认证后添加银行卡")
					return
				}
				if (!this.form.cardNo) {
					this.$util.showInfoToast("请输入你的银行卡号")
					return
				}
				if(this.form.cardNo.length>=15){
					this.form = Object.assign(this.form, getBankInfoByCardNo(this.form.cardNo));
				}
				if(!this.form.bankName){
					this.$util.showInfoToast("请输入正确的银行卡号")
					return
				}
				this.submitAddress = true
				this.$util.doPostJson('/wx/saveBindingYHK', this.form, {}, true).then(res => {
					this.submitAddress = false
					console.log("添加成功",res.data.code)
					if (res.data.code === this.$ResponseStatus.OK) {
						this.$util.showSuccessToast('添加成功')
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 1500)
					} else {
						this.$util.showInfoToast(res.data.message)
					}
				})
			}
		}
		
	}
</script>

<style lang="scss">
	page{
		background: #f8f8f8;
		padding-top: 16upx;
	}
	$base-color: #F85057;
	$font-color-light: #909399;
	
	
	.zy-required::before {
		content: '*';
		color: #dd524d;
	}
	
	/*边框*/
	.b-b:after,
	.b-t:after {
		position: absolute;
		z-index: 3;
		left: 0;
		right: 0;
		height: 0;
		content: '';
		transform: scaleY(.5);
		border-bottom: 1px solid #EEEEEE;
	}
	
	.b-b:after {
		bottom: 0;
	}
	
	.zy-title{
		width: 100%;
		margin: 100rpx 0rpx;
		text-align: center;
		font-size: 32rpx;
	}
	.zy-head-img {
		margin: 10upx auto;
		text-align: center;
	}
	
	.zy-head-img image {
		border-radius: 50%;
		width: 200upx;
		height: 200upx;
	}
	.zy-intro{
		width: 100%;
		padding: 30rpx 30rpx;
		background-color: #FFFFFF;
		.text{
			width: 100%;
			height: 300rpx;
			border: solid 1rpx #e3e3e3;
			border-radius: 15rpx;
			padding: 10rpx 10rpx;
		}
	}
	.business-scope{
		width: 100%;
		height: 150rpx;
		border: solid 1rpx #e3e3e3;
		border-radius: 15rpx;
		padding: 10rpx 10rpx;
	}
	
	.subject-type{
		width: 400rpx;
		height: 50rpx;
		line-height: 50rpx;
	}
	.row{
		display: flex;
		align-items: center;
		position: relative;
		padding:30rpx 30upx;
		background: #fff;
		
		.tit{
			width: 160rpx;
			flex-shrink: 0;
			font-size: 30upx;
			color: #303133;
		}
		.input{
			flex: 1;
			font-size: 30upx;
			color: $font-color-light;
		}
		.icon-shouhuodizhi{
			font-size: 36upx;
			color: $font-color-light;
		}
	}
	.default-row{
		margin-top: 16upx;
		.tit{
			flex: 1;
		}
		switch{
			transform: translateX(16upx) scale(.9);
		}
	}
	.add-btn{
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		margin: 60upx auto;
		font-size: 32rpx;
		color: #fff;
		background-color: $base-color;
		border-radius: 10upx;
		box-shadow: 1px 2px 5px rgba(70, 70, 70, 0.4);
	}
</style>
